package com.zch.book.service.impl;

import java.util.HashMap;
import java.util.Map;

import com.zch.book.dao.UserDao;
import com.zch.book.dao.impl.UserDaoImpl;
import com.zch.book.entity.User;
import com.zch.book.service.UserService;

public class UserServiceImpl implements UserService {
	UserDao ud = new UserDaoImpl();
	@Override
	public Map<String, Object> login(String name,String pwd) {
		Map<String,Object> map = new HashMap<String,Object>();
		User user = ud.getUserByName(name);
		if(user != null){//用户存在
			if(user.getPwd().equals(pwd)){//密码正确
				map.put("isLogin", true);//登录成功还是失败的验证
				map.put("user1", user);//存放正确的用户对象
			}else{//密码错误
				map.put("isLogin", false);
				map.put("errorMsg", "密码错误");
			}
		}else{//用户不存在
			map.put("errorMsg", "用户名不存在");
			map.put("isLogin", false);
		}
		return map;
	}

}
